package com.xishu.dao.jpa;

import com.xishu.entity.shop.Item;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface ItemDao extends JpaRepository<Item, Long>, JpaSpecificationExecutor<Item> {
    /**
     * 取消售罄标记
     *
     * @param shopId
     * @return
     */
    @Modifying
    @Transactional
    @Query("update  item set saleOut = null  where shopId=:shopId  ")
    public void cleanSalOut(long shopId);

    @Query("select  count(*) from item m where m.online=:online and entity=:entity and flagDelete=:flagDelete")
//    @Query("select  count(*) from item m where m.online=:online and entity=:entity")
    public long countOnlineItem(Boolean online, Boolean entity, Boolean flagDelete);

    /**
     * 清空锁定量
     *
     * @param shopId
     */
    @Modifying
    @Transactional
    @Query("update  item set lockCount = 0  where shopId=:shopId  ")
    public void cleanLockCount(Long shopId);
}
